{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c3a765cc-761d-4543-a260-2acdd2daf37f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x是正数\n",
      "本语句在内程序块\n",
      "本语句在外程序块\n"
     ]
    }
   ],
   "source": [
    "x = 1\n",
    "if x > 0:\n",
    "    print(\"x是正数\")\n",
    "    print(\"本语句在内程序块\")\n",
    "\n",
    "\n",
    "print(\"本语句在外程序块\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a6bf0f33-1528-4278-a931-d906d771f590",
   "metadata": {},
   "outputs": [],
   "source": [
    "if x:\n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ce891de5-849a-49c0-9957-f3c5870b43b1",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "unexpected indent (2394060065.py, line 3)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn[7], line 3\u001b[1;36m\u001b[0m\n\u001b[1;33m    print(\"本语句在内程序块\")\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unexpected indent\n"
     ]
    }
   ],
   "source": [
    "if x > 0:\n",
    "    print(\"x是正数\")\n",
    "      print(\"本语句在内程序块\")\n",
    "\n",
    "print(\"本语句在外程序块\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f28e9d1f-8ff3-421d-ad54-96a7e5771c4c",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "unindent does not match any outer indentation level (<tokenize>, line 3)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m<tokenize>:3\u001b[1;36m\u001b[0m\n\u001b[1;33m    print(\"本语句在内程序块\")\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unindent does not match any outer indentation level\n"
     ]
    }
   ],
   "source": [
    "if x > 0:\n",
    "      print(\"x是正数\")\n",
    "    print(\"本语句在内程序块\")\n",
    "\n",
    "print(\"本语句在外程序块\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "bec9bf0e-9395-4491-8351-dbad368ac2d6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x是正数\n",
      "本语句在内程序块\n"
     ]
    }
   ],
   "source": [
    "a = 10\n",
    "if x > 0:\n",
    "    print(\"x是正数\")          # 缩进使用空白字符\n",
    "    print(\"本语句在内程序块\")  # 缩进使用制表字符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "c03e6986-2cde-45dd-9b14-4f9d6a707c8e",
   "metadata": {},
   "outputs": [
    {
     "ename": "TabError",
     "evalue": "inconsistent use of tabs and spaces in indentation (2308007785.py, line 4)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn[20], line 4\u001b[1;36m\u001b[0m\n\u001b[1;33m    print(\"本语句在内程序块\")  # 缩进使用制表字符\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mTabError\u001b[0m\u001b[1;31m:\u001b[0m inconsistent use of tabs and spaces in indentation\n"
     ]
    }
   ],
   "source": [
    "a = 10\n",
    "if x > 0:\n",
    "    print(\"x是正数\")          # 缩进使用空白字符\n",
    "\tprint(\"本语句在内程序块\")  # 缩进使用制表字符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "72a8e6c1-c6f6-40d6-b24b-2e5e54d819f0",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "unindent does not match any outer indentation level (<tokenize>, line 4)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m<tokenize>:4\u001b[1;36m\u001b[0m\n\u001b[1;33m    print(a)           # 缩进使用空白字符\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unindent does not match any outer indentation level\n"
     ]
    }
   ],
   "source": [
    "a = 10\n",
    "if a > 0:\n",
    "\tprint(\"The num: \") # 缩进使用制表字符\n",
    "    print(a)           # 缩进使用空白字符\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "949e9f8f-a726-455a-8e31-3e5042737d68",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "180ea5ab-49f9-49d7-bacf-95f87b38283b",
   "metadata": {},
   "source": [
    "$ \\mathrm{BMI} < 18.5$为体重过轻，$18.5 \\le \\mathrm{BMI} < 24$为正常体重，\n",
    "$24 \\le \\mathrm{BMI} < 28$为过重，$\\mathrm{BMI} \\ge 28$ 即为肥胖。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "c0e1b2dc-f11f-4b09-8551-3e83d2bf4fe1",
   "metadata": {},
   "outputs": [],
   "source": [
    "weight = 90\n",
    "height = 1.72"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "2fb64c3e-1512-4be9-92e8-b46834eb1e86",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BMI: 30.42, 肥胖\n"
     ]
    }
   ],
   "source": [
    "bmi = weight / (height**2)\n",
    "\n",
    "if bmi < 18.5:\n",
    "    bmi_kind = '过轻'\n",
    "elif bmi < 24:\n",
    "    bmi_kind = '正常'\n",
    "elif bmi < 28:\n",
    "    bmi_kind = '过重'\n",
    "else:\n",
    "    bmi_kind = '肥胖'\n",
    "\n",
    "print(f\"BMI: {bmi:0.2f}, {bmi_kind}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "ff2f8798-3d9c-4552-a453-82fd5274602f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BMI: 30.42, 肥胖\n"
     ]
    }
   ],
   "source": [
    "bmi = weight / (height**2)\n",
    "\n",
    "if bmi < 24:\n",
    "    if bmi < 18.5:\n",
    "        bmi_kind = '过轻'\n",
    "    else:\n",
    "        bmi_kind = '正常'    \n",
    "else:\n",
    "    if bmi < 28:\n",
    "        bmi_kind = '过重'\n",
    "    else:\n",
    "        bmi_kind = '肥胖'\n",
    "\n",
    "print(f\"BMI: {bmi:0.2f}, {bmi_kind}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
